/* 运动函数的封装 */
export const useBannerMove = (ele, options, fn) => {
  let number = 0
  for (const k in options) {
    number++
    k === 'opacity'
      ? (options[k] = options[k] * 100)
      // eslint-disable-next-line no-self-assign
      : (options[k] = options[k])
    const timer = setInterval(function() {
      let start
      k === 'opacity'
        ? (start = window.getComputedStyle(ele)[k] * 100)
        : (start = parseInt(window.getComputedStyle(ele)[k]))
      let MovingDistance = (options[k] - start) / 10
      MovingDistance > 0
        ? (MovingDistance = Math.ceil((options[k] - start) / 10))
        : (MovingDistance = Math.floor((options[k] - start) / 10))
      if (start === options[k]) {
        clearInterval(timer)
        number--
        if (number === 0) {
          fn && fn()
        }
      } else {
        k === 'opacity'
          ? (ele.style[k] = (start + MovingDistance) / 100)
          : (ele.style[k] = MovingDistance + start + 'px')
      }
    }, 20)
  }
}
